package com.sch.www.ele.services.impl;


import com.sch.www.codeGenerator.base.BaseServicesSimpleImp;
import com.sch.www.codeGenerator.base.CustomPage;
import com.sch.www.ele.entity.CareUnit;
import com.sch.www.ele.entity.CareUnitExample;
import com.sch.www.ele.entity.CareUser;
import com.sch.www.ele.mapper.CareUnitMapper;
import com.sch.www.ele.services.CareUnitServices;
import com.sch.www.ele.services.CareUserServices;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Transient;
import org.springframework.stereotype.Service;

@Service
public class CareUnitServicesImpl extends BaseServicesSimpleImp<CareUnit, CareUnitExample, CareUnitMapper, CareUnitServices> implements CareUnitServices {

    @Autowired
    CareUserServices careUserServices;

    @Override
    protected CareUnitExample getExampleNewInstance() {
        return new CareUnitExample();
    }

    @Override
    protected String getTableName() {
        return null;
    }

    @Override
    public CustomPage<CareUnit> list(String name, String creditCode, int pageNum, int pageSize) {
        CareUnitExample example = new CareUnitExample();
        CareUnitExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(name)) {
            criteria.andNameLike(likePacking(name));
        }
        if (StringUtils.isNotBlank(creditCode)) {
            criteria.andCreditCodeLike(likePacking(creditCode));
        }
        return getMapper().selectByExampleStartPage(example, pageNum, pageSize);
    }

    @Transient
    @Override
    public void insertSelective(String liaisonName, String liaisonPhoneNumber, CareUnit careUnit) {
        CareUser careUser = new CareUser();
        careUser.setName(liaisonName);
        careUser.setPhoneNumber(liaisonPhoneNumber);
        careUserServices.insertSelective(careUser);
        insertSelective(careUnit);
    }
}
